home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / common / MultiImage.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  7KB  |  243 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from util import print_timing
  5. from util import to_storage
  6. import util
  7. import syck
  8. import wx
  9.  
  10. class MultiImage(object):
  11.     
  12.     def __init__(self, image_list):
  13.         self.images = []
  14.         self.tags = { }
  15.         SplitImage2 = SplitImage2
  16.         import SplitImage2
  17.         self.images = [ SplitImage2(image) for image in image_list ]
  18.         for image in self.images:
  19.             if 'anchors' in image.image_dictionary:
  20.                 for anchor in image.image_dictionary.anchors:
  21.                     if 'tag' in anchor and anchor['tag'] is not None:
  22.                         self.tags[anchor['tag']] = image
  23.                         continue
  24.                     []
  25.                 
  26.             []
  27.         
  28.  
  29.     
  30.     def __contains__(self, tagname):
  31.         return tagname in self.tags
  32.  
  33.     
  34.     def tag_rect(self, tagname):
  35.         if tagname not in self.tags:
  36.             raise ValueError('tag %s not in this MultiImage' % tagname)
  37.         
  38.         return self.drawrects[self.tags[tagname]]
  39.  
  40.     
  41.     def make_bitmap(self, width, height, mask_color = wx.BLACK):
  42.         bitmap = wx.EmptyBitmap(width, height)
  43.         if not hasattr(self, 'temp_dc'):
  44.             self.temp_dc = wx.MemoryDC()
  45.         
  46.         self.temp_dc.SelectObject(bitmap)
  47.         self.draw(self.temp_dc, wx.Rect(0, 0, width, height))
  48.         self.temp_dc.SelectObject(wx.NullBitmap)
  49.         bitmap.SetMask(wx.Mask(bitmap, mask_color))
  50.         return bitmap
  51.  
  52.     
  53.     def draw(self, dc, rect):
  54.         self.drawrects = { }
  55.         _[1]
  56.         self.region = wx.Region(0, 0, 0, 0)
  57.         one = False
  58.         for image in self.images:
  59.             drect = wx.Rect(*self.drawrects[image])
  60.             drect.Offset((rect.x, rect.y))
  61.             if dc:
  62.                 image.draw(dc, drect)
  63.                 self.region.UnionRegion(image.region)
  64.                 continue
  65.             []
  66.         
  67.  
  68.     
  69.     def compute_rect(self, image, dcrect):
  70.         myanchors = image.get_anchors_to()
  71.         numanchors = len(myanchors)
  72.         if image.image_dictionary.style != 'static':
  73.             if numanchors == 1:
  74.                 anchorfrom = to_storage(myanchors[0])
  75.                 tag = anchorfrom.to
  76.                 imageto = self.tags[tag]
  77.                 anchorto = [](_[1][0])
  78.                 rectto1 = self.drawrects[imageto]
  79.                 rectto2 = (0, 0, dcrect.width, dcrect.height)
  80.                 positionto1 = compute_anchor_position(anchorto, rectto1[2:], rectto1[:2])
  81.                 positionto2 = compute_anchor_position(get_SI2_anchor(image), rectto2[2:], rectto2[:2])
  82.                 positionfrom1 = compute_anchor_position(anchorfrom, [
  83.                     image.imgw,
  84.                     image.imgh], [
  85.                     0,
  86.                     0])
  87.                 positionfrom2 = (0, 0)
  88.                 diffxto = abs(positionto1[0] - positionto2[0])
  89.                 diffyto = abs(positionto1[1] - positionto2[1])
  90.                 diffxlocal = abs(positionfrom1[0] - positionfrom2[0])
  91.                 diffylocal = abs(positionfrom1[1] - positionfrom2[1])
  92.                 increasex = diffxto - diffxlocal
  93.                 increasey = diffyto - diffylocal
  94.                 newsizew = image.imgw + increasex
  95.                 newsizeh = image.imgh + increasey
  96.                 newlocalanchorposition = positionto2
  97.                 positiontodrawat = (positionfrom2[0] + newlocalanchorposition[0], positionfrom2[1] + newlocalanchorposition[1])
  98.                 self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], newsizew, newsizeh)
  99.                 return None
  100.             elif numanchors == 2:
  101.                 (anchorfrom1, anchorfrom2) = myanchors
  102.                 tag1 = anchorfrom1['to']
  103.                 tag2 = anchorfrom2['to']
  104.                 imageto1 = self.tags[tag1]
  105.                 imageto2 = self.tags[tag2]
  106.                 anchorto1 = _[2]
  107.                 anchorto2 = _[3]
  108.                 rectto1 = self.drawrects[imageto1]
  109.                 rectto2 = self.drawrects[imageto2]
  110.                 positionto1 = compute_anchor_position(anchorto1, rectto1[2:], rectto1[:2])
  111.                 positionto2 = compute_anchor_position(anchorto2, rectto2[2:], rectto2[:2])
  112.                 positionfrom1 = compute_anchor_position(anchorfrom1, [
  113.                     image.imgw,
  114.                     image.imgh], [
  115.                     0,
  116.                     0])
  117.                 positionfrom2 = compute_anchor_position(anchorfrom2, [
  118.                     image.imgw,
  119.                     image.imgh], [
  120.                     0,
  121.                     0])
  122.                 diffxto = abs(positionto1[0] - positionto2[0])
  123.                 diffyto = abs(positionto1[1] - positionto2[1])
  124.                 diffxlocal = abs(positionfrom1[0] - positionfrom2[0])
  125.                 diffylocal = abs(positionfrom1[1] - positionfrom2[1])
  126.                 increasex = diffxto - diffxlocal
  127.                 increasey = diffyto - diffylocal
  128.                 newsizew = image.imgw + increasex
  129.                 newsizeh = image.imgh + increasey
  130.                 newlocalanchorposition = compute_anchor_position(anchorfrom1, newsizew, newsizeh, [
  131.                     0,
  132.                     0])
  133.                 positiontodrawat = (positionto1[0] - newlocalanchorposition[0], positionto1[1] - newlocalanchorposition[1])
  134.                 self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], newsizew, newsizeh)
  135.                 return None
  136.             else:
  137.                 raise AssertionError('invalid skin, wrong number (%d) of anchors for image of type %s!' % (numanchors, image.image_dictionary['style']))
  138.         elif numanchors == 0:
  139.             positiontodrawat = compute_anchor_position(get_SI2_anchor(image), (dcrect.width, dcrect.height), [
  140.                 0,
  141.                 0])
  142.             self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], image.imgw, image.imgh)
  143.             return None
  144.         elif numanchors == 1:
  145.             anchorfrom = image.get_anchors_to()[0]
  146.             tag = anchorfrom['to']
  147.             imageto = self.tags[tag]
  148.             anchorto = _[4]
  149.             rectto = self.drawrects[imageto]
  150.             positionto = compute_anchor_position(anchorto, rectto[2:], rectto[:2])
  151.             positionfrom = compute_anchor_position(anchorfrom, [
  152.                 image.imgw,
  153.                 image.imgh], [
  154.                 0,
  155.                 0])
  156.             positiontodrawat = (positionto[0] - positionfrom[0], positionto[1] - positionfrom[1])
  157.             self.drawrects[image] = (positiontodrawat[0], positiontodrawat[1], image.imgw, image.imgh)
  158.             return None
  159.         else:
  160.             raise AssertionError('invalid skin, wrong number (%d) of anchors for image of type %s!' % (numanchors, image.image_dictionary['style']))
  161.  
  162.  
  163.  
  164. def compute_anchor_position(anchor, size, offset):
  165.     if 'halign' in anchor:
  166.         halign = anchor.halign
  167.     else:
  168.         halign = 'left'
  169.     if 'valign' in anchor:
  170.         valign = anchor.valign
  171.     else:
  172.         valign = 'top'
  173.     if 'offset' in anchor:
  174.         off = anchor.offset
  175.     else:
  176.         off = [
  177.             0,
  178.             0]
  179.     if isinstance(off[0], int):
  180.         myoffsetx = off[0]
  181.     else:
  182.         myoffsetx = int(str(off[0])[:-1]) * size[0] / 100
  183.     if isinstance(off[1], int):
  184.         myoffsety = off[1]
  185.     else:
  186.         myoffsety = int(str(off[1])[:-1]) * size[1] / 100
  187.     off = [
  188.         myoffsetx,
  189.         myoffsety]
  190.     tup = (offset[0], offset[1], size[0], size[1])
  191.     if halign == 'left':
  192.         x = 0
  193.     elif halign == 'right':
  194.         x = tup[2]
  195.     else:
  196.         x = tup[2] / 2
  197.     x = x + tup[0] + off[0]
  198.     if valign == 'top':
  199.         y = 0
  200.     elif valign == 'bottom':
  201.         y = tup[3]
  202.     else:
  203.         y = tup[3] / 2
  204.     y = y + tup[1] + off[1]
  205.     return (x, y)
  206.  
  207.  
  208. def get_SI2_anchor(image):
  209.     retval = to_storage({ })
  210.     if hasattr(image.image_dictionary, 'offset'):
  211.         retval['offset'] = image.image_dictionary.offset
  212.     
  213.     if hasattr(image.image_dictionary, 'valign'):
  214.         retval['valign'] = image.image_dictionary.valign
  215.     
  216.     if hasattr(image.image_dictionary, 'halign'):
  217.         retval['halign'] = image.image_dictionary.halign
  218.     
  219.     return retval
  220.  
  221.  
  222. def main(images):
  223.     temp_dc = wx.MemoryDC()
  224.     temp_dc.SelectObject(destbitmap)
  225.     mimg = MultiImage(images)
  226.     drawrect = wx.Rect(10, 10, 220, 440)
  227.     mimg.draw(temp_dc, drawrect)
  228.     temp_dc.SelectObject(wx.NullBitmap)
  229.  
  230. if __name__ == '__main__':
  231.     import util
  232.     from skins import images as imgmngr
  233.     from skins import skins
  234.     app = wx.PySimpleApp()
  235.     skins.res_path = '../../res/'
  236.     destbitmap = imgmngr.get('skins/default/blue-flower.jpg')
  237.     f = file('../../res/skins/skinExample')
  238.     images = to_storage(syck.load(f)).Images
  239.     f.close()
  240.     util.profile(main, images)
  241.     destbitmap.SaveFile('C:/workspace/Digsby/res/skins/default/output.png', wx.BITMAP_TYPE_PNG)
  242.  
  243.